define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'factor/carbon_factor/index' + location.search,
                    add_url: 'factor/carbon_factor/add',
                    edit_url: 'factor/carbon_factor/edit',
                    del_url: 'factor/carbon_factor/del',
                    multi_url: 'factor/carbon_factor/multi',
                    import_url: 'factor/carbon_factor/import',
                    table: 'carbon_factor',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'sn', title: __('Sn'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'category_id', title: __('Category_id'),searchList: Config.categoryNameList,formatter: Table.api.formatter.normal},

                        {field: 'carbon_factor_result', title: __('Carbon_factor_result'),searchable:false,  class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'carbon_factor_result_kg', title: __('Carbon_factor_result_kg'),searchable:false, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type', title: __('Type'),searchList: {'1':__('Type_product'), '2':__('Type_material')}, formatter: Table.api.formatter.normal},
                        {field: 'is_account', title: __('Is_account'),searchList: {'0':__('Not_certified'), '1':__('Certified')}, formatter: Table.api.formatter.status},
                        {field: 'account_time', title: __('Account_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_authority', title: __('Is_authority'),searchList: {'0':__('Not_certified'), '1':__('Certified')}, formatter: Table.api.formatter.status},
                        {field: 'authority_time', title: __('Authority_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'product_review', title: __('Product_review'),searchList: {'0':__('Status hidden'), '1':__('Status normal'),'2':__('Status rejected')}, formatter: Table.api.formatter.status},
                        {field: 'review_time', title: __('Review_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'),searchList: {'0':__('Hidden'), '1':__('Normal')},url:'factor/carbon_factor/toggle', formatter: Table.api.formatter.toggle},
                        {field: 'price', title: __('Price'),searchable:false},
                        {field: 'sales', title: __('Sales'),searchable:false},
                        {field: 'lifecycle', title: __('Lifecycle'),searchList: Config.lifecycleType, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
